<template>
  <div id="app">
    <header class="head">
      <a class="back tl" href="javascript:history.back(-1)">
        <i class="el-icon-arrow-left"></i>
      </a>
      <a href="javascript:;" class="tc">
        <small class="font_18 co_f">修改密码</small>
      </a>
      <a href="javascript:;" class="save">
        <button @click="submitForm()" type="primary">保存</button>
      </a>
    </header>
    <main>
      <div class="formcontent">
        <ul>
          <li>
            <span> <em>*</em>原始密码</span>
            <div class="froms">
              <input type="password" v-model="oldpassword">
            </div>
          </li>
          <li>
            <span><em>*</em>新密码{{value}}</span>
            <div class="froms">
              <input type="password" v-model="newpassword">
            </div>
          </li>
          <li>
            <span> <em>*</em>确认密码</span>
            <div class="froms">
              <input type="password" v-model="newpasswordagain">
            </div>
          </li>
        </ul>
      </div>
  
    </main>
  </div>
</template>

<script>
  import {
    ChangePassWord
  } from '../../api/api'
  export default {
    data() {
      return {
        oldpassword: '',
        newpassword: '',
        newpasswordagain: '',
      };
    },
  
    methods: {
      validate: function() {
        // if (this.oldpassword != 0 && this.newpassword != 0 && this.newpasswordagain != 0) {
        //   this.$message.error("文本框不能为空");
        //   if (this.newpassword !== this.newpasswordagain) {
        //     this.$message.error("请确认重置的密码相同");
        //   }
        //   if (this.oldpassword != JSON.parse(localStorage.getItem('auth')).password) {
        //     this.$message.error("密码错误");
        //   }
        // }
      },
      submitForm: function() {
        if (this.oldpassword == '' && this.newpassword == '' && this.newpasswordagain == '') {
          this.$message.error("文本框不能为空");
        } else if (this.newpassword !== this.newpasswordagain) {
          this.$message.error("请确认重置的密码相同");
        } else if (this.oldpassword != JSON.parse(localStorage.getItem('auth')).password) {
          this.$message.error("密码错误");
        } else {
          //定义需要传给通讯的参数： unid    
          let options = {
            params: {
              userUnid: JSON.parse(localStorage.getItem('auth')).UserUnid,
              originalPassWord: this.oldpassword,
              newPassWord: this.newpassword,
            }
          }
          //调取接口
          ChangePassWord(options).then((res) => {
            if (res.success === true) {
              this.$router.push({
                name: 'Login'
              });
            } else {
              this.$message.error(res.msg);
            }
          })
        }
  
  
  
      },
    },
    created() {
  
    },
  }
</script>

<style lang="scss">
  
</style>
